
var	SleepTotal=0;
var	ImgTotal=0, ImgNums=0;

//删除图片
//得到大小
function DelImg(i) {
	var file=document.getElementById("upfile"+i);
	var prev=document.getElementById("prev"+i);
	var view=document.getElementById("hidimg"+i);
	var isize=document.getElementById("size"+i);
	if(view.src=="" || file.value=="" || isize.innerHTML=="") return false;	
	var delfile=document.getElementById("file"+i);
	delfile.innerHTML="\n<input type=file id=upfile"+i+ " name=upfile"+i+" size=30 onchange='ShowImg("+i+", this)'>";

	prev.src="";
	view.src="";
	isize.innerHTML='';
}

function SleepImg(num) {
        if(SleepTotal>10) return false;
        var view=document.getElementById("hidimg"+num);
        var isize=document.getElementById("size"+num);
        if(view.readyState=="complete") {
			if(view.fileSize>1024*1024*2) {
				alert("该图片超过2M，请使用高级上传方式上传");
				DelImg(num);
				return false;
			}

            isize.innerHTML="(图片大小:"+Math.ceil(view.fileSize/1024)+"K)";
        }       
        else setTimeout("SleepImg("+num+")", 1000);
}
//显示图片
function ShowImg(num,obj){
	if(obj.value=="") return false;
	var view=document.getElementById("hidimg"+num);
	view.src=obj.value;
	if(obj.value.search(/\.jpg|\.jpeg|\.bmp|\.gif|\.emf|\.wmf|\.xbm|\.png$/i) == -1) {
		alert("文件格式不正确");
		var delfile=document.getElementById("file"+num);
		delfile.innerHTML="<input type=file id=upfile"+num+ " name=upfile"+num+" size=30 onchange='ShowImg("+num+", this)'>";
		return false;
	}
	var prev=document.getElementById("prev"+num);
	var isize=document.getElementById("size"+num);
	if(view.readyState=="complete") {
		if(view.fileSize>1024*1024*2) {
			alert("该图片超过2M，请使用高级上传方式上传");
			DelImg(num);
			return false;
		}

		isize.innerHTML="(大小:"+Math.ceil(view.fileSize/1024)+"K)";
	}
	else setTimeout("SleepImg("+num+")", 1000);
	prev.src=obj.value;
}
//上传文件
function SendImg(obj){
	//alert(is_ie7());
	for(var i=1; i<7; i++) {
		var file=document.getElementById("upfile"+i);
		if(file.value!="" && file.value!="http://"  ) {
			if (!is_ie7())
			{
				var prev=document.getElementById("prev"+i);
				var view=document.getElementById("hidimg"+i);
				if(view.readyState!="complete") {
					alert(i+" 不是有效图片");
					var delfile=document.getElementById("file"+i);
					delfile.innerHTML="<input type=file id=upfile"+i+ " name=upfile"+i+" size=30 onchange='ShowImg("+i+", this)'>";
					prev.src="";
					view.src="";
					continue;
				}
			}
			ImgNums++;
		}
	}
	if(ImgNums<=0) {
		alert('请选择一个图片');
		return false;
	}
	if (!is_ie7())
	{
		var bar=document.getElementById("upimg");
		bar.style.display ='';
		var btn = document.getElementById("submitbtn");
		btn.value='正在上传...';
		btn.disabled=true;
	}else{
		var btn = document.getElementById("submitbtn");
		btn.value='正在上传...';
		btn.disabled=true;
	}
	return true;
}

function is_ie7(){
	var browser_name = navigator.appName;
	var browser_ver  = navigator.appVersion;
	var ver_array    = browser_ver.split(";");
	if (browser_name.indexOf("Internet Explorer") != -1)
	{
		if (ver_array.length > 1 && ver_array[1].length > 0  )
		{
			var ie_ver = parseInt(ver_array[1].replace("MSIE",""));
			if (ie_ver == 7)
			{
				return true;
			}
		}
	}
	return false;
}